package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.exception.BusinessException;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Dept;
import com.itheima.pojo.Emp;
import com.itheima.pojo.Student;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService{
    @Autowired
    private EmpMapper empMapper;
    @Override
    public void removeDeptById(Integer id) {
        //如果部门下有员工，不允许删除
        LambdaQueryWrapper<Emp> queryWrapper = new LambdaQueryWrapper<Emp>().eq(Emp::getDeptId, id);
        if (empMapper.selectCount(queryWrapper) > 0){
            throw new BusinessException("该部门下有员工，不允许删除");
        }
        removeById(id);
    }
}
